package org.ihelpuoo.weboo.util;

import java.io.InputStream;
import java.util.Locale;

import org.ihelpuoo.io.CharInputStream;
import org.ihelpuoo.parser.segment.CharSegment;
import org.ihelpuoo.parser.segment.Segment;
import org.ihelpuoo.parser.segment.ServletCharSegmentFactory;
import org.ihelpuoo.weboo.WebooUtils;
import org.ihelpuoo.weboo.module.ModuleContext;

public class XMLPatternFactory extends ServletCharSegmentFactory
{

	public XMLPatternFactory(ModuleContext context, Locale locale)
	{
		this.context = context;
		this.locale = locale;
	}

	private ModuleContext	context;
	private Locale			locale;

	public Locale getLocale()
	{
		return locale;
	}

	public void setLocale(Locale locale)
	{
		this.locale = locale;
	}

	@Override
	protected Segment parseSegment(InputStream ins) throws Exception
	{
		Segment seg = WebooUtils.formatSegment(context,locale,new CharSegment(ins));
		ins = new CharInputStream(seg.toString());
		return super.parseSegment(ins);
	}

}
